package org.tema.entities;

import java.io.Serializable;
import java.sql.Date;
import java.util.ArrayList;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;

import org.tema.Priority;
import org.tema.Status;
import org.tema.Type;
import javax.persistence.Table;
import javax.persistence.Column;
import javax.persistence.JoinColumn;

/**
 * Entity implementation class for Entity: TestCase
 *
 */

@Entity 
@Table(name="TESTCASE")
public class TestCase implements Serializable {

	
	private int id;
	private String summary;
	private String environment;
	private String preSteps;
	private String description;
	private String expectedResult;
	private ArrayList <Integer>  bugId;
	private Date creationDate;
	private Date modificationDate;
	private byte[] attachment;
	private Priority priority;
	private Type type;
	private Status status;
	private double executionTime;
	
	/* Add relational properties for TestSpecification, Testers, TestCases, TestPlans;
	   Reports relationship has been removed because the report is per TestPlan run, Specification
	   if a report's generated for a product not clear for what run an what specification.
	   Appropriate searches need to be added at business layer.
	*/
	protected Product product;
	protected TestSpecification specification;
	
	protected User creator;
	protected User modifier;
	protected Set<TestPlan> testPlanSet;

	



	private static final long serialVersionUID = 1L;

	public TestCase() {
		super();
	}  
	
	@Id    
	@GeneratedValue
	@Column(name="ID")
	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}   
	
	@Column(name="SUMMARY")
	public String getSummary() {
		return this.summary;
	}

	public void setSummary(String summary) {
		this.summary = summary;
	}  
	
	@Column(name="ENVIRONMENT")
	public String getEnvironment() {
		return this.environment;
	}

	public void setEnvironment(String environment) {
		this.environment = environment;
	}  
	
	@Column(name="PRESTEPS")
	public String getPreSteps() {
		return this.preSteps;
	}

	public void setPreSteps(String preSteps) {
		this.preSteps = preSteps;
	}   
	
	@Column(name="DESCRIPTION")
	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	} 
	
	@Column(name="EXPECTEDRESULT")
	public String getExpectedResult() {
		return this.expectedResult;
	}

	public void setExpectedResult(String expectedResult) {
		this.expectedResult = expectedResult;
	}  
	
 
	



	@Column(name="BUGID")
	public ArrayList<Integer> getBugId() {
		return bugId;
	}

	public void setBugId(ArrayList<Integer> bugId) {
		this.bugId = bugId;
	}

	@Column(name="CREATIONDATE")
	public Date getCreationDate() {
		return this.creationDate;
	}

	public void setCreationDate(Date creationDate) {
		this.creationDate = creationDate;
	}  
	
	@Column(name="MODIFICATIONDATE")
	public Date getModificationDate() {
		return this.modificationDate;
	}

	public void setModificationDate(Date modificationDate) {
		this.modificationDate = modificationDate;
	}  
	
	@Column(name="ATTACHMENT")
	public byte[] getAttachment() {
		return this.attachment;
	}

	public void setAttachment(byte[] attachment) {
		this.attachment = attachment;
	} 
	
	@Enumerated
	@Column(name="PRIORITY")
	public Priority getPriority() {
		return priority;
	}

	public void setPriority(Priority priority) {
		this.priority = priority;
	}
	
	@Enumerated
	@Column(name="TYPE")
	public Type getType() {
		return type;
	}

	public void setType(Type type) {
		this.type = type;
	}
	
	@Enumerated
	@Column(name="STATUS")
	public Status getStatus() {
		return status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}

	
	@Column(name="EXECUTIONTIME")
	public double getExecutionTime() {
		return executionTime;
	}

	public void setExecutionTime(double executionTime) {
		this.executionTime = executionTime;
	}

	// references to product
	@ManyToOne( cascade= {CascadeType.PERSIST, CascadeType.MERGE })
	@JoinColumn(name="PRODUCT_ID", referencedColumnName = "ID")
	public Product getProduct() {
		return product;
	}

	public void setProduct(Product product) {
		this.product = product;
	}

	
	//references to test specification
	@ManyToOne( cascade= {CascadeType.PERSIST, CascadeType.MERGE })
	@JoinColumn(name="SPECIFICATION_ID", referencedColumnName = "ID")
	public TestSpecification getSpecification() {
		return specification;
	}

	public void setSpecification(TestSpecification specification) {
		this.specification = specification;
	}
	
	@ManyToOne (  cascade= {CascadeType.PERSIST, CascadeType.MERGE },optional = false )
	@JoinColumn(name="CREATOR_ID", referencedColumnName = "ID")
	public User getCreator() {
		return creator;
	}

	public void setCreator(User creator) {
		this.creator = creator;
	}
	
	@ManyToOne( cascade= {CascadeType.PERSIST, CascadeType.MERGE })
	@JoinColumn(name="MODIFIER_ID", referencedColumnName = "ID")
	public User getModifier() {
		return modifier;
	}

	
	public void setModifier(User modifier) {
		this.modifier = modifier;
	}

	@ManyToMany( cascade= {CascadeType.PERSIST, CascadeType.MERGE }, mappedBy="testCaseSet"  )
	public Set<TestPlan> getTestPlanSet() {
		return testPlanSet;
	}

	public void setTestPlanSet(Set<TestPlan> testPlanSet) {
		this.testPlanSet = testPlanSet;
	}
	
}
